package com.ruoyi.law.util;

import com.aliyun.dysmsapi20170525.models.SendSmsRequest;
import com.aliyun.dysmsapi20170525.models.SendSmsResponse;
import com.aliyun.tea.TeaModel;
import com.aliyun.teaopenapi.models.Config;
import com.ruoyi.common.utils.StringUtils;

import java.util.HashMap;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class AliyunSendSms {

	public static final String ACCESSKEYID = "LTAI5tJBfLoDjhgth45kfKgL";
	public static final String ACCESSKEYSECRET = "QV2HYF6HJlakg9QDODVYSmVRAO51Qh";
	public static  String SIGNNAME = "CATL合格证";
	//专家提示
	public static final String EXPERT_QUEST = "SMS_478580836";
	//监管任务提示
	public static final String SUPERVISE_QUEST = "SMS_478605795";
	//证书审核通过
	public static final String CERTIFICATE_SUCCESS = "SMS_478650260";

	//证书通过评审提示
	public static final String CERTIFICATE_EXAMINE = "SMS_478385835";

	//证书到期提醒
	public static final String CERTIFICATE_EXPIRE= "SMS_478415811";


	/**
	 * 使用AK&SK初始化账号Client
	 *
	 * @return Client
	 * @throws Exception
	 */
	public static com.aliyun.dysmsapi20170525.Client createClient() throws Exception {
		Config config = new Config()
				// 您的AccessKey ID
				.setAccessKeyId(ACCESSKEYID)
				// 您的AccessKey Secret
				.setAccessKeySecret(ACCESSKEYSECRET);
		// 访问的域名
		config.endpoint = "dysmsapi.aliyuncs.com";
		return new com.aliyun.dysmsapi20170525.Client(config);
	}


	//专家提示
public static Map<String, Object>  sendExpertQuest(String mobile, String userName) {
		String content = "{\"name\":\""+userName+"\"}";
		com.aliyun.dysmsapi20170525.Client client;
		 Map<String, Object> map = new HashMap<String, Object>();
		 map.put("code", "500");
		 map.put("msg", "发送失败！");
	try {
			client = AliyunSendSms.createClient();
			SendSmsRequest sendSmsRequest = new SendSmsRequest();
			sendSmsRequest.setPhoneNumbers(mobile);
			sendSmsRequest.setSignName(SIGNNAME);
			sendSmsRequest.setTemplateCode(EXPERT_QUEST);
			System.out.println(content);
			sendSmsRequest.setTemplateParam(content);
			SendSmsResponse resp = client.sendSms(sendSmsRequest);
			if("OK".equals(resp.getBody().getCode())) {
				 map.put("code", "0");
				 map.put("msg", "发送成功！");

			}
			com.aliyun.teaconsole.Client.log(com.aliyun.teautil.Common.toJSONString(TeaModel.buildMap(resp)));
		} catch (Exception e) {
			e.printStackTrace();
		}
		return map;
	}
	//监管任务提示
public static Map<String, Object>  sendSuperviseQuest(String mobile, String userName) {
		String content = "{\"name\":\""+userName+"\"}";
		com.aliyun.dysmsapi20170525.Client client;
		 Map<String, Object> map = new HashMap<String, Object>();
		 map.put("code", "500");
		 map.put("msg", "发送失败！");
	try {
			client = AliyunSendSms.createClient();
			SendSmsRequest sendSmsRequest = new SendSmsRequest();
			sendSmsRequest.setPhoneNumbers(mobile);
			sendSmsRequest.setSignName(SIGNNAME);
			sendSmsRequest.setTemplateCode(SUPERVISE_QUEST);
			System.out.println(content);
			sendSmsRequest.setTemplateParam(content);
			SendSmsResponse resp = client.sendSms(sendSmsRequest);
			if("OK".equals(resp.getBody().getCode())) {
				 map.put("code", "0");
				 map.put("msg", "发送成功！");

			}
			com.aliyun.teaconsole.Client.log(com.aliyun.teautil.Common.toJSONString(TeaModel.buildMap(resp)));
		} catch (Exception e) {
			e.printStackTrace();
		}
		return map;
	}
	//证书审核通过
	public static Map<String, Object>  sendCertificateSuccess(String mobile, String deptName,String createDate) {
		String content = "{\"depetName\":\""+deptName+"\",\"createDate\":\""+createDate+"\"}";
		com.aliyun.dysmsapi20170525.Client client;
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("code", "500");
		map.put("msg", "发送失败！");
		try {
			client = AliyunSendSms.createClient();
			SendSmsRequest sendSmsRequest = new SendSmsRequest();
			sendSmsRequest.setPhoneNumbers(mobile);
			sendSmsRequest.setSignName(SIGNNAME);
			sendSmsRequest.setTemplateCode(CERTIFICATE_SUCCESS);
			System.out.println(content);
			sendSmsRequest.setTemplateParam(content);
			SendSmsResponse resp = client.sendSms(sendSmsRequest);
			if("OK".equals(resp.getBody().getCode())) {
				map.put("code", "0");
				map.put("msg", "发送成功！");

			}
			com.aliyun.teaconsole.Client.log(com.aliyun.teautil.Common.toJSONString(TeaModel.buildMap(resp)));
		} catch (Exception e) {
			e.printStackTrace();
		}
		return map;
	}
	//CERTIFICATE_EXAMINE
	public static Map<String, Object>  sendCertificateExamine(String mobile, String deptName) {
		String content = "{\"deptName\":\""+deptName+"\"}";
		com.aliyun.dysmsapi20170525.Client client;
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("code", "500");
		map.put("msg", "发送失败！");
		try {
			client = AliyunSendSms.createClient();
			SendSmsRequest sendSmsRequest = new SendSmsRequest();
			sendSmsRequest.setPhoneNumbers(mobile);
			sendSmsRequest.setSignName(SIGNNAME);
			sendSmsRequest.setTemplateCode(CERTIFICATE_EXAMINE);
			System.out.println(content);
			sendSmsRequest.setTemplateParam(content);
			SendSmsResponse resp = client.sendSms(sendSmsRequest);
			if("OK".equals(resp.getBody().getCode())) {
				map.put("code", "0");
				map.put("msg", "发送成功！");

			}
			com.aliyun.teaconsole.Client.log(com.aliyun.teautil.Common.toJSONString(TeaModel.buildMap(resp)));
		} catch (Exception e) {
			e.printStackTrace();
		}
		return map;
	}


//证书到期提醒
	public static Map<String, Object>  sendCertificateExpire(String mobile, String deptName,String createDate,String endDate) {
		String content = "{\"deptName\":\""+deptName+"\",\"createDate\":\""+createDate+"\",\"endDate\":\""+endDate+"\"}";
		com.aliyun.dysmsapi20170525.Client client;
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("code", "500");
		map.put("msg", "发送失败！");
		try {
			client = AliyunSendSms.createClient();
			SendSmsRequest sendSmsRequest = new SendSmsRequest();
			sendSmsRequest.setPhoneNumbers(mobile);
			sendSmsRequest.setSignName(SIGNNAME);
			sendSmsRequest.setTemplateCode(CERTIFICATE_EXPIRE);
			System.out.println(content);
			sendSmsRequest.setTemplateParam(content);
			SendSmsResponse resp = client.sendSms(sendSmsRequest);
			if("OK".equals(resp.getBody().getCode())) {
				map.put("code", "0");
				map.put("msg", "发送成功！");

			}
			com.aliyun.teaconsole.Client.log(com.aliyun.teautil.Common.toJSONString(TeaModel.buildMap(resp)));
		} catch (Exception e) {
			e.printStackTrace();
		}
		return map;
	}
	public static boolean isValidPhoneNumber(String phoneNumber) {
		if (StringUtils.isEmpty(phoneNumber)){
			return false;
		}
		// 正则表达式：以1开头，第二位为3-9之间的数字，后面9位数字
		String regex = "^[1][3-9]\\d{9}$";

		// 创建 Pattern 对象
		Pattern pattern = Pattern.compile(regex);
		// 创建 matcher 对象
		Matcher matcher = pattern.matcher(phoneNumber);

		// 判断是否匹配
		return matcher.matches();
	}
/*
	public static void main(String[] args) {
		//sendExpertQuest("15998761771","张三");
		//sendSuperviseQuest("15998761771","张三");
		//sendCertificateExamine("15998761771","济南市同翔信息");
		//sendCertificateSuccess("15998761771","济南市同翔信息","2025年10月1日");
		//sendCertificateExpire("15998761771","济南市同翔信息","2025年10月1日","2025年7月1日");
	}
*/

}
